#include <iostream>
#include <queue>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;
const int M = 1e5 + 5;

int n, m;
int s, t, k;
int head[N], rhead[N];
int ver[M << 1], W[M << 1], Next[M << 1], tot;
void add(int head[], int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
struct Node {
  int d, v;
  bool operator<(Node o) const { return d > o.d; }
};
struct Node2 {
  int s, d, v;
  bool operator<(Node2 o) const { return s > o.s; }
};
int h[N];
void dijkstra() {
  rep(i, 1, n) h[i] = 0x3f3f3f3f;
  priority_queue<Node> pq;
  pq.push(Node{0, t});
  h[t] = 0;
  while (pq.size()) {
    Node now = pq.top();
    pq.pop();
    int u = now.v;
    int d = now.d;
    if (d > h[u]) continue;
    for (int i = rhead[u]; i; i = Next[i]) {
      int v = ver[i];
      int w = W[i];
      if (h[v] > h[u] + w) {
        h[v] = h[u] + w;
        pq.push(Node{h[v], v});
      }
    }
  }
}
int cnt[N];
int astar() {
  priority_queue<Node2> pq;
  pq.push(Node2{h[s], 0, s});
  while (pq.size()) {
    Node2 now = pq.top();
    pq.pop();
    int u = now.v;
    cnt[u]++;
    if (cnt[t] == k) return now.d;
    for (int i = head[u]; i; i = Next[i]) {
      int v = ver[i];
      int w = W[i];
      int d = now.d + w;
      if (cnt[v] < k) pq.push(Node2{d + h[v], d, v});
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    int u, v, w;
    cin >> u >> v >> w;
    add(head, u, v, w);
    add(rhead, v, u, w);
  }
  cin >> s >> t >> k;
  if (s == t) k++;
  dijkstra();
  cout << astar();
  return 0;
}